package com.zelin.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * Created by WF on 2020/11/2 11:56
 * 掌握：与zuul区别，zuul会自动对一些敏感的请求头进行拦截，这个全局过滤器不会
 */
@Configuration
@Slf4j
public class CustomGlobalFilter implements GlobalFilter, Ordered {
    //1.实现过滤器的业务
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        log.info("正在执行自定义全局过滤器。");
        return chain.filter(exchange);
    }
    //2.过滤时执行的时机，值越小，越早执行
    @Override
    public int getOrder() {
        return 0;
    }
}
